
import request from '@/utils/request'

const api = {
    getReceiptConfig: '/v1/receipt/config/detail', // 获取发票抬头配置信息
    updateReceiptConfig: '/v1/receipt/config/detail/update', // 修改发票抬头配置
    getReceiptAddress: '/v1/receipt/address/page/list', // 获取发票地址列表
    createReceiptAddress: '/v1/receipt/address/create', // 创建发票地址
    updateReceiptAddress: '/v1/receipt/address/update', // 修改发票地址
    setReceiptAddressDefault: '/v1/receipt/address/default/', // 设置收货地址为默认地址
    deleteReceiptAddress: '/v1/receipt/address/delete/', // 删除地址
    getReceiptAddressDefault: '/v1/receipt/address/default', // 获取默认发票收件地址
    createReceipt: '/v1/receipt/create', // 创建发票
    cancelReceipt: '/v1/receipt/cancel/', // 撤销发票申请
}

// 获取发票抬头配置信息
export function getReceiptConfig (parameter) {
    return request({
        url: api.getReceiptConfig,
        method: 'get',
        headers: {
            'name':'getReceiptConfig',
        },
        params: parameter
    })
}

// 修改发票抬头配置
export function updateReceiptConfig (parameter) {
    return request({
        url: api.updateReceiptConfig,
        method: 'post',
        headers: {
            'name':'getReceiptConfig',
        },
        data: parameter
    })
}

// 获取发票地址列表数据
export function getReceiptAddress (parameter) {
    return request({
        url: api.getReceiptAddress,
        method: 'get',
        headers: {
            'name':'getReceiptAddress',
        },
        params: parameter
    })
}

// 创建发票地址
export function createReceiptAddress (parameter) {
    return request({
        url: api.createReceiptAddress,
        method: 'post',
        headers: {
            'name':'createReceiptAddress',
        },
        data: parameter
    })
}

// 修改发票地址
export function updateReceiptAddress (parameter) {
    return request({
        url: api.updateReceiptAddress,
        method: 'post',
        headers: {
            'name':'updateReceiptAddress',
        },
        data: parameter
    })
}

// 设为收货地址为默认地址
export function setReceiptAddressDefault (receiptAddressId) {
    return request({
        url: api.setReceiptAddressDefault + receiptAddressId,
        method: 'post',
        headers: {
            'name':'setReceiptAddressDefault',
        },
        data: {}
    })
}

// 删除发票收货地址
export function deleteReceiptAddress (receiptAddressId) {
    return request({
        url: api.deleteReceiptAddress + receiptAddressId,
        method: 'post',
        headers: {
            'name':'deleteReceiptAddress',
        },
        data: {}
    })
}

// 获取默认发票收件地址
export function getReceiptAddressDefault () {
    return request({
        url: api.getReceiptAddressDefault,
        method: 'get',
        headers: {
            'name':'getReceiptAddressDefault',
        },
        params: {}
    })
}

// 创建发票
export function createReceipt (parameter) {
    return request({
        url: api.createReceipt,
        method: 'post',
        headers: {
            'name':'createReceipt',
        },
        data: parameter
    })
}

// 撤销发票申请
export function cancelReceipt (receiptId) {
    return request({
        url: api.cancelReceipt + receiptId,
        method: 'post',
        headers: {
            'name':'cancelReceipt',
        },
        data: {}
    })
}